import React from 'react'
import {WxSDK} from '../components/wechat'
import request from '../request'



const getSignature = (url) => {
  return request(`/wechat/getJSApiSignature?url=${url}`)
}
/**
 * 微信配置
 *
 * @param {string} href window.location.href
 * @returns
 */
function configWx (href) {
  const url = encodeURIComponent(href);
  getSignature(url)
    .then(result => {
      wx.config({
        debug: false,
        appId: result.app_id,
        timestamp: result.timestamp,
        nonceStr: result.nonce_str,
        signature: result.signature,
        jsApiList: [
          'onMenuShareTimeline',
          'onMenuShareAppMessage'
        ] // 必填，需要使用的JS接口列表
      });
    }).then(() =>{
      wx.ready(() => {
        configWxShare()
      })
    }).then(() => {
    wx.error(function(res){
      console.log(res)

    })
  })
}

/**
 * 配置微信分享
 */
function configWxShare () {
  const shareConfig = {
    title: '高考志愿，用百科出奇制胜',
    desc: '量化专业前景，4000万考生就业数据参考，助力志愿填报',
    link: 'http://baike.weidingzhi.net/index',
    imgUrl: 'http://baike.weidingzhi.net/dist/logo.jpg'
  };
  WxSDK(shareConfig)
}




 const onEnter = () => {
    const { href } = window.location;
    configWx(href)
  };
export  {onEnter}


